package com.chunayev.numerology.util;

import java.awt.Color;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Collections;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.ResourceBundle;

/**
 * @author Sergey Chunayev
 */
public class Constants {
    
    public static final Properties ALPHABETS_PROPERTIES = new Properties();
    
    public static final Properties APPLICATION_PROPERTIES = new Properties();
    
    public static final Map<Character, Integer> CHAR_TO_INDEX_RU;
    
    public static final Color COLOR_ROW_EVEN = new Color(230, 230, 250);
    
    public static final Color COLOR_ROW_ODD = new Color(240, 240, 250);
    
    public static final String ENV_HOME = "berkeley.env.home";
    
    public static final Color mainPositionColor = new Color(250, 150, 150);
    
    public static final Color otherPositionColor = new Color(150, 150, 250);
    
    public static final String REGEXP;
    
    public static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle
            .getBundle("com.chunayev.numerologic.resources.i18n.i18n",
                    new Locale("ru"));
    
    public static final Color[] COLORS = { Color.red, Color.orange,
            Color.yellow, Color.green, Color.cyan, Color.blue,
            new Color(150, 50, 200) };
    
    public static final int ROW_COUNT = 7;
    
    static {
        try {
            // ALPHABETS_PROPERTIES.load(ClassLoader
            // .getSystemResourceAsStream("alphabets.properties"));
            // APPLICATION_PROPERTIES.load(ClassLoader
            // .getSystemResourceAsStream("application.properties"));
            APPLICATION_PROPERTIES.load(new FileInputStream(
                    "config/application.properties"));
            ALPHABETS_PROPERTIES.load(new FileInputStream(
                    "config/alphabets.properties"));
        } catch (final IOException e) {
            throw new RuntimeException(e);
        }
        
        final String ruAlphabet = ALPHABETS_PROPERTIES
                .getProperty("ru.alphabet");
        final char[] ruAlphabetChars = ruAlphabet.toCharArray();
        final Map<Character, Integer> charToIndexRu = new HashMap<Character, Integer>();
        for (int i = 0; i < ruAlphabetChars.length; i++) {
            charToIndexRu.put(ruAlphabetChars[i], i + 1);
        }
        CHAR_TO_INDEX_RU = Collections.unmodifiableMap(charToIndexRu);
        
        REGEXP = String.format("[^%s]+", ALPHABETS_PROPERTIES
                .getProperty("ru.regexp"));
        
    }
}
